package ar.uade.distribuidas.tpo.web.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ar.uade.distribuidas.tpo.servicios.VentasServiceImpl;

/**
 * Servlet implementation class Facturar
 */
@WebServlet("/Facturar")
@MultipartConfig(fileSizeThreshold=1024*1024*2, // 2MB
maxFileSize=1024*1024*10,      // 10MB
maxRequestSize=1024*1024*50)   // 50MB
public class Facturar extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Facturar() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		  RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/facturar.jsp");
		    			
			Long cuil = Long.valueOf(request.getParameter("cuil"));
			
			try{
								
			request.setAttribute("xmlgen1", VentasServiceImpl.getInstancia().generarVenta(cuil));
			request.setAttribute("allok", "La solicitud fue procesada correctamente.");
			
			 request.getRequestDispatcher("/jsp/facturar.jsp").forward(request, response);
			
			} catch (Exception e) {
			
				request.setAttribute("allerror", "Hubo un error al procesar la solicitud.");
				request.getRequestDispatcher("/jsp/facturar.jsp").forward(request, response);
				
			} 
	}

}
